//
//  FeedbackViewController.m
//  JunZeWristband
//
//  Created by Kendama on 2017/8/17.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "FeedbackViewController.h"
#import "FIDPlaceholderTextView.h"
#import "FeedBackApi.h"

@interface FeedbackViewController ()

@property (strong, nonatomic)  FIDPlaceholderTextView *suggestTextView;
@property(nonatomic,strong) UIButton *commitButton;

@end

@implementation FeedbackViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)dealloc
{
    
}

- (void)refreshBaseControlValue
{
    
}

#pragma mark - 点击事件
- (void)didClickCommitButton
{
    [self.view endEditing:YES];
    
    if (self.suggestTextView.text.length == 0 ) {
        
        [SVProgressHUD showInfoWithStatus:MyNSLocalizedString(@"反馈内容不能为空") maskType:SVProgressHUDMaskTypeBlack];
        return;
    }
    
    if ([self.suggestTextView.text isEqualToString:MyNSLocalizedString(@"感谢您反馈宝贵的意见")]) {
        
        [SVProgressHUD showInfoWithStatus:MyNSLocalizedString(@"反馈内容不能为空") maskType:SVProgressHUDMaskTypeBlack];
        return;
    }
    
    if ([NSString isContainsTwoEmoji:self.suggestTextView.text] ) {
        [SVProgressHUD showInfoWithStatus:MyNSLocalizedString(@"意见不能使用表情")];
        return;
    }
    
    NSString *feedback = [self.suggestTextView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    FeedBackApi *api = [[FeedBackApi alloc]initWith:@{@"content":feedback}];
    
    [api dtDefaultInterceptStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        NSDictionary *dic = [api responseJSONObject];
        if ([dic[@"errcode"] intValue] == 0) {
            [SVProgressHUD showInfoWithStatus:MyNSLocalizedString(@"感谢您的反馈！")];
        }else{
            [SVProgressHUD showInfoWithStatus:dic[@"errmsg"]];
        }
    } failure:nil];

}

#pragma mark - 事件处理

#pragma mark - 代理


#pragma mark - 通知处理

#pragma mark - 初始化
- (void)setNavigationStyle
{
    [self setNavigationBarTitle:MyNSLocalizedString(@"用户反馈")];
}

- (void)masLayoutSubview
{
    __weak UIView *superView = self.view;
    superView.backgroundColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1];
    [self.suggestTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView).with.offset(px1920Height(286));
        make.left.mas_equalTo(superView).with.offset(px1080Width(53));
        make.right.mas_equalTo(superView).with.offset(-px1080Width(53));
        make.height.mas_equalTo(px1920Height(500));
    }];
    
    [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.suggestTextView.mas_bottom).with.offset(px1920Height(109));
        make.centerX.mas_equalTo(superView.mas_centerX);
    }];
}

- (FIDPlaceholderTextView *)suggestTextView
{
    if(!_suggestTextView)
    {
        UIView *superView = self.view;
        _suggestTextView = [[FIDPlaceholderTextView alloc]init];
        _suggestTextView.font = [UIFont systemFontOfSize:14];
        [superView addSubview:_suggestTextView];
        _suggestTextView.layer.cornerRadius = 5;
        _suggestTextView.layer.borderColor = [UIColor colorWithRed:234/255.0 green:234/255.0 blue:234/255.0 alpha:1].CGColor;
        _suggestTextView.layer.borderWidth = 1;
    }
    return _suggestTextView;
}

- (UIButton *)commitButton
{
    if(!_commitButton)
    {
        UIView *superView = self.view;
        _commitButton = [[UIButton alloc]init];
        [superView addSubview:_commitButton];
        [_commitButton setTitle:MyNSLocalizedString(@"提交") forState:UIControlStateNormal];
        [_commitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_commitButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
        [_commitButton setBackgroundImage:[UIImage imageNamed:@"but_login"] forState:UIControlStateNormal];
        [_commitButton addTarget:self action:@selector(didClickCommitButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _commitButton;
}

@end
